package com.zyajac.springBootDemo.service.Impl;

import com.zyajac.springBootDemo.commonUtils.CommonUtils;
import com.zyajac.springBootDemo.enums.ResultEnum;
import com.zyajac.springBootDemo.service.TestService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("TestService")
public class TestServiceImpl implements TestService {

    /**测试用并发变量*/
    private Integer currentVariable  = 0 ;


    /**
     *@author LZG
     *@date   2019/8/21
     *@return map
     */
    @Override
    public Map<String , Object> curVarTest(){
        String version = String.valueOf(currentVariable);
        String newVersion = null;
        while(currentVariable == 0){
            synchronized (this){
                newVersion = String.valueOf(currentVariable);
                this.currentVariable = 1;
            }
        }
        if(version.equals(newVersion)){
            return CommonUtils.setResult(ResultEnum.OK,"成功");
        }
        return  CommonUtils.setResult(ResultEnum.FAIL ,"失败");
    }

}
